package modules

import (
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var DB *gorm.DB
var err error

func init() {
	usr := "root"
	pass := "Lyf123456@"
	ip := "114.115.208.52"
	port := "3306"
	database := "beego"
	dbs := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True&loc=Local", usr, pass, ip, port, database)
	DB, err = gorm.Open(mysql.Open(dbs), &gorm.Config{
		SkipDefaultTransaction: true, //关闭事务
	})
	if err != nil {
		panic("failed to connect database")
	}

	DB.AutoMigrate(&User{}, &Role{}, &Pic{}, &Auth{}, &Article{}, &ArticleCate{}, &UserRole{}, &Events{})
}
